// src/utils/utils.ts

export function SET_TOKEN(token: string) {
  localStorage.setItem("access-token", `Bearer ${token}`);
}
export function GET_TOKEN() {
  return localStorage.getItem("access-token")?.replace("Bearer ", "");
}
export function REMOVE_TOKEN() {
  localStorage.removeItem("access-token");
}

export function SET_REFRESH_TOKEN(refreshToken: string) {
  localStorage.setItem("refresh-token", `Bearer ${refreshToken}`);
}
export function GET_REFRESH_TOKEN() {
  return localStorage.getItem("refresh-token")?.replace("Bearer ", "");
}
export function REMOVE_REFRESH_TOKEN() {
  localStorage.removeItem("refresh-token");
}

export function SaveToken(headers: any) {
  const accessToken = headers["access_token"] || headers["authorization"];
  accessToken && SET_TOKEN(accessToken);
  const refreshToken = headers["refresh_token"] || headers["x_authorization"];
  refreshToken && SET_REFRESH_TOKEN(refreshToken);
}
export function Logout() {
  REMOVE_TOKEN();
  REMOVE_REFRESH_TOKEN();
}
